package com.springcloud;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
// 该注解向服务中心注册
@EnableDiscoveryClient
// 开启Hystrix 断路器
@EnableHystrix
// 也是开启断路器
@EnableCircuitBreaker
// 开启断路器仪表盘
@EnableHystrixDashboard
public class EurekaRibbonApplication {
    private static final Logger LOGGER = LoggerFactory.getLogger(EurekaRibbonApplication.class) ;

    public static void main(String[] args) {
        SpringApplication.run(EurekaRibbonApplication.class, args);
        LOGGER.info("Eureka Ribbon 服务消费者启动成功！");
    }


    /**
     *  @LoadBalanced 为Bean restTemplate 开启负载均衡的功能
     *  在消费者调用注册的服务时就会使用负载均衡的策略
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
